#!/bin/bash
#********************************************************************
#Name:          test
#Date:          2024-08-26
#FileName：     init_lnmp.sh
#Description:   The test script
#********************************************************************
yum -y install make  cmake gcc gcc-c++ flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel gd freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel unzip libcap lsof  epel-release  autoconf automake pcre-devel libxml2-devel

echo "安装nginx===============================================" 

mkdir /usr/local/src
echo pcre
tar zxvf pcre-8.41.tar.gz -C /usr/local/src/
echo  创建Nginx运行用户
useradd -M -s /sbin/nologin nginx
echo 解压Nginx
tar zxvf nginx-1.12.2.tar.gz  -C /usr/local/src/
cd /usr/local/src/ngin*
./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module  --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx
make -j 6 && make -j 6 install
tree

echo "安装php===============================================" 
yum -y install epel-release
yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c
cd /usr/local
tar zxf php-7.1.10.tar.gz -C /usr/local/src

cd /usr/local/src/php-7.1.10

./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --with-gd --without-pear --enable-fpm

make -j 6 && make -j 6 install

cd /usr/local/php/etc/
cp -a php-fpm.conf.default php-fpm.conf
echo 修改php-fpm的配置文件
sed -i '17a\pid = run/php-fpm.pid' /usr/local/php/etc/php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp -a www.conf.default www.conf
sed -i '23,24s/nobody/nginx/' www.conf
echo 启动

sed -i  '
71a\
location ~ \.php$ { \
    root           html; \
    fastcgi_pass   127.0.0.1:9000; \
    fastcgi_index  index.php; \
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; \
    include        fastcgi.conf; \
}
' /usr/local/nginx/conf/nginx.conf

cd /usr/local/nginx/html/

cat > index.php  << EOF
<?php
         phpinfo();
 ?>
EOF

systemctl stop firewalld
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm

